package com.zjc.utils.collection;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zjc.utils.date.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;

public class KeyLinkedBlockingQueueAddThread implements Runnable {

    private static final Logger logger = LoggerFactory.getLogger(KeyLinkedBlockingQueueAddThread.class);
    private static Gson gson = new GsonBuilder()
            .setDateFormat("yyyy-MM-dd HH:mm:ss")
            .create();

    @Override
    public void run() {

        while (true) {
            KeyLinkedBlockingQueueValue value = new KeyLinkedBlockingQueueValue();
            value.setUniqueNo(new Random().nextInt(100) + "");
            value.setTime(DateUtils.getCurrentTimeStr());
            try {
                KeyLinkedBlockingQueueTest.add(value);
                logger.info("添加元素：{}", gson.toJson(value));
            } catch (InterruptedException e) {
                logger.error("添加元素异常：{}", e.getCause(), e);
            }
        }
    }

}
